import sun.misc.ProxyGenerator;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Date: 2019/3/6
 * Time: 11:05
 * User: Driss.
 */
public class Main {

    interface UserManager{
        void query();
    }

    static class UserManagerImpl implements UserManager{
        public void query() {
            System.out.println("query user");
        }
    }


    interface InfManager{
        void del();
        void add();
    }

    static class InfManagerImpl implements InfManager{

        public void del() {
            System.out.println("query del");
        }

        public void add() {
            System.out.println("query add");
        }
    }

    static class MyInvationHandler implements InvocationHandler{

        //被代理类，也就是委托类
        Object realSubject;

        public MyInvationHandler(Object realSubject) {
            this.realSubject = realSubject;
        }

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

            before();
            Object res = method.invoke(realSubject,args);
            after();
            return res;
        }



        public void before(){
            System.out.println("执行代理类相关逻辑之前");
        }

        public void after(){
            System.out.println("执行代理类逻辑之后");
        }
    }


    public static void main(String[] args) {

        //step1:生成被代理类对象
        UserManager userManager = new UserManagerImpl();

        //step2:
        MyInvationHandler invationHandler = new MyInvationHandler(userManager);

    }

}
